package cn.butcher21.utils;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * butcher create in 2021/05/07/11:15
 */
public class Day7 {
    public static ObservableList<String> get() {
        ObservableList<String> list = FXCollections.observableArrayList();
        Calendar calendar = Calendar.getInstance();
        Date time;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        for (int i = 0; i < 7; i++) {
            calendar.setTimeInMillis(System.currentTimeMillis() - 60 * 60 * 24 * 1000 * i);
            time = calendar.getTime();
            String format = sdf.format(time);
            list.add(format);
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(getNow());
        System.out.println(getNowBefore7());
    }

    public static String getNow() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        return sdf.format(new Date());
    }

    public static String getNowBefore7() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        long millis = System.currentTimeMillis();
        Date date = new Date(millis - 1000 * 60 * 60 * 24 * 7);
        return sdf.format(date);
    }

}
